package com.lbj.googleplay.googleplay100.ui.holder;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lbj.googleplay.googleplay100.R;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

public class MoreHolder extends BaseHolder<Integer> {

    //加载更多的几种状态
    //1.可以加载更多
    //2.加载更多失败
    //3.无更多数据
    public static final int STATE_MORE_MORE = 1;
    public static final int STATE_MORE_ERROR = 2;
    public static final int STATE_MORE_NONE = 3;
    private LinearLayout ll_loadMore;
    private TextView tv_loadError;

    public MoreHolder(boolean hasMore) {
        //如果有更多数据,状态为STATE_MORE_MORE,将此状态传递给父类的data,父类会同时刷新界面
        if (hasMore){
            setData(STATE_MORE_MORE);
        }else {
            setData(STATE_MORE_NONE);

        }
    }

    @Override
    public View initView() {
        View view = UIUtils.inflate(R.layout.list_item_more);
        ll_loadMore = view.findViewById(R.id.ll_loadMore);
        tv_loadError = view.findViewById(R.id.tv_loadError);
        return view;
    }

    @Override
    public void refreshView(Integer data) {
        switch (data){
                case STATE_MORE_MORE:
                //显示加载更多
                    ll_loadMore.setVisibility(View.VISIBLE);
                    tv_loadError.setVisibility(View.GONE);
                break;

                case STATE_MORE_NONE:
                //无数据,都不显示
                    ll_loadMore.setVisibility(View.GONE);
                    tv_loadError.setVisibility(View.GONE);
                break;

                case STATE_MORE_ERROR:
                //显示加载失败
                    ll_loadMore.setVisibility(View.GONE);
                    tv_loadError.setVisibility(View.VISIBLE);
                break;
                default:
                    break;
        }
    }

}
